/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.view.model;

import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;

/**
 * The model for categories ComboxBox
 * 
 * @author Can
 */
public class CategoriesComboBoxModel
        extends AbstractListModel implements ComboBoxModel {

    private List<String> categories;
    private int selectedIndex;

    public CategoriesComboBoxModel(List<String> categories) {
        this.categories = categories;
        this.categories.add(0, "<Select>");
        this.selectedIndex = 0;
    }

    public void setSelectedItem(Object anItem) {
        this.selectedIndex = categories.indexOf(anItem);
    }

    public Object getSelectedItem() {
        return categories.get(selectedIndex);
    }

    public int getSize() {
        return categories.size();
    }

    public Object getElementAt(int index) {
        return categories.get(index);
    }
}
